def main():
    children = input().split()
    n = len(children)
    
    if n == 1:
        print(children[0][0])
        return
    
    classes = {1:[], -1:[]}
    
    classes[1].append(children[0][0])
    c = 1
    for child in children[1:]:
        if child[2] == 'Y':
            classes[c].append(child[0])
        else:
            c *= -1
            classes[c].append(child[0])
    
    classes[1].sort()
    classes[-1].sort()        
    if classes[-1][0] < classes[1][0]:
        print(" ".join(classes[-1]))
        print(" ".join(classes[1]))
    else:
        print(" ".join(classes[1]))
        print(" ".join(classes[-1]))
    

if __name__ == "__main__":
    main()